package cn.sm1234.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {

    //list.jsp
    @RequestMapping("/list")
    public String list(){
        System.out.println("run list....4");
        return "list";
    }

    @RequestMapping("/add")
    public String add(){
        // springboot默认已经处理错误
        // 如果要自己定义， 需要在templates/error.html来处理, 这是惯例
        int i = 100/0;
        return  "list";
    }

    @RequestMapping("/update")
    public String update(){
        String name = null;
        name.toUpperCase(); // 空指针错误
        return  "list";
    }

  /*  // java.lang.ArithmeticException
    @ExceptionHandler(value = {java.lang.ArithmeticException.class})
    public ModelAndView handlerArithmeticException(Exception e){
        ModelAndView mv = new ModelAndView();
        mv.addObject("exception", e.toString());
        mv.setViewName("error1");
        return mv;
    }

    // java.lang.NullPointerException
    @ExceptionHandler(value = {java.lang.NullPointerException.class})
    public ModelAndView handlerNullPointerException(Exception e){
        ModelAndView mv = new ModelAndView();
        mv.addObject("exception", e.toString());
        mv.setViewName("error2");
        return mv;
    }*/
}
